/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.deployment.manager.editar;

import br.com.deployment.entidade.empresa.Cartorio;
import br.com.deployment.entidade.humana.Titular;
import br.com.deployment.entidade.localidade.Endereco;
import br.com.deployment.entidade.registroimovel.GeoRef;
import br.com.deployment.message.Msg;
import br.com.deployment.servico.CartorioServico;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author luciano
 */
@ManagedBean
@SessionScoped
public class ManagerEditarCartorio implements Serializable{
    
    @EJB
    CartorioServico cartorioServico;
    
    private Cartorio cartorio;
    private Endereco endereco;
    private Titular titular;
    private Endereco enderecoTitular;
    
    private List<GeoRef> lstGeoRef;
    
    public void atualizar(){
        this.cartorio.setEndereco(this.endereco);
        this.titular.setEndereco(this.enderecoTitular);
        this.cartorio.setTitular(this.titular);
        cartorioServico.atualizar(cartorio);
        Msg.messagemInfo("Cartorio salvo com sucesso.");
    }
    
    public void editar(Cartorio c){
            this.cartorio = c;
            this.endereco = c.getEndereco();
            this.titular = c.getTitular();
            this.enderecoTitular = this.titular.getEndereco();
            this.lstGeoRef = cartorio.getGeoAtuacao();
            
    }
    
     public void redirect(String string, Cartorio cartorio) {
        try {
            FacesContext context = FacesContext.getCurrentInstance();
            this.editar(cartorio);
            context.getExternalContext().redirect(string);
        } catch (IOException ex) {
            Logger.getLogger(ManagerEditarCartorio.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
     
      public void addGeoRef(){
          lstGeoRef.add(new GeoRef());
        
    }
    public void removeGeoRef(GeoRef gf){
        lstGeoRef.remove(gf);
    }

    public List<GeoRef> getLstGeoRef() {
        return lstGeoRef;
    }

    public void setLstGeoRef(List<GeoRef> lstGeoRef) {
        this.lstGeoRef = lstGeoRef;
    }
    
    

    public Cartorio getCartorio() {
        return cartorio;
    }

    public void setCartorio(Cartorio cartorio) {
        this.cartorio = cartorio;
    }

    public Endereco getEndereco() {
        return endereco;
    }

    public void setEndereco(Endereco endereco) {
        this.endereco = endereco;
    }

    public Endereco getEnderecoTitular() {
        return enderecoTitular;
    }

    public void setEnderecoTitular(Endereco enderecoTitular) {
        this.enderecoTitular = enderecoTitular;
    }

    public Titular getTitular() {
        return titular;
    }

    public void setTitular(Titular titular) {
        this.titular = titular;
    }
     
     
    
}
